#include <cstdio>
#include <queue>
#include <iostream>
using namespace std;
priority_queue <int> q;
int n;
int main() {
	scanf ("%d", &n);
	char c;
	int a;
	for (int i = 1; i <= n; i++) {
		scanf ("\n%c", &c);
		if (c == 'i') {
			scanf ("%d", &a);
			q.push(-a);
		} else {
			printf ("%d\n", -q.top());
			q.pop();
		}
	}
	return 0;
}
